// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import "userDatabase.js" as UserList
Rectangle {
    width: 300
    height: 600
    color: "#00000000"
    id: main
    property variant currentUserIndex: 0
    signal userSelected()
    signal addUserClicked
    function addUser(){
        model.append({"title": addUserInput.text})
        UserList.addUser(addUserInput.text);
        addUserClicked();
    }
    function removeUser(){
        model.remove(currentUserIndex);
    }

    Rectangle{
        id: addRect
        width:300
        height:100
        anchors.bottom: parent.bottom
        color:"#00000000"
        Rectangle{
            id:images
            x:0;y:0
            height:parent.height
            color: "#00000000"
            width:parent.width
            Image{
                id: addUserImage
                x: 30
                y: 13
                source:"Assets/Login/newuser.png"
                height: 75
                width:75
                smooth: true
                visible: true
                MouseArea{
                    x:0
                    y:0
                    width:parent.width
                    height: parent.height
                    onClicked: {images.visible=false;acceptUserRect.visible=true;}
                }
            }

        }
        Rectangle{
            id: acceptUserRect
            x: 257
            y: 0
            height: parent.height
            color: "#00000000"
            width: 48
            visible:false;
            TextInput{
                id: addUserInput
                x: -245
                y: 26
                text: qsTr("text here")
                horizontalAlignment: TextInput.AlignHCenter
                font.pixelSize: 24
            }

            Image{
                x: -75
                y: 47
                source: "Assets/Login/okay.png"
            }

            MouseArea{
                id: acceptUserClick
                x: -75
                y: 47
                width:48
                height: 48
                onClicked:{addUser();acceptUserRect.visible=false;images.visible=true;}
            }

            Image {
                id: image1
                x: -12
                y: 47
                width: 48
                height: 48
                smooth: true
                source: "Assets/Login/okay_es.png"
                MouseArea{
                    id: accept_esUserClick
                    x: 0
                    y: 0
                    width:48
                    height: 48
                    onClicked:{addUser();acceptUserRect.visible=false;images.visible=true;}
                }
            }
        }
    }
    Rectangle {
      id: container
      width: parent.width; height: 500
      color: "#00000000"
      Component {
        id: delegate
        Item {
          id: userItem
          width: parent.width; height: 80
          Rectangle{
              id: userRect
              width:parent.width; height:80;color: "#00000000"
              MouseArea{
                  x:0;y:0;height:parent.height;width:parent.width
                  onClicked:{userSelected();}
              }

              Image {
                height: 75; width: 75;
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                source: "Assets/Login/guy.png"
              }
              Text {
                x: 100
                text: title
                font.bold: true
                font.pixelSize: 28
                anchors.verticalCenter: parent.verticalCenter
              }
              /*
              Image{
                  id: removeUserImag
                  anchors.verticalCenter: parent.verticalCenter
                  source:"Assets/Login/removeuser.png"
                  height: 75
                  anchors.right: parent.right
                  width:75
                  smooth: true
                  visible: true
                  MouseArea{
                      x:0
                      y:0
                      width:parent.width
                      height: parent.height
                      onClicked: {currentUserIndex=index;removeUser();}
                  }
              }*/
            }
        }

      }
      ListView {
        id: view
        anchors.fill: parent
        model: model
        delegate: delegate
      }

      ListModel {
        id: model
        ListElement {
          title: "Westin"
        }

      }
    }
    XmlListModel{
        id: xmlUserModel
        source: "Assets/Login/data.xml"
        query: "/system/note"
        XmlRole {name: "name"; query: "name/string()"}
    }
}
//Westin
